//
//  MoreViewController.m
//  51-Tour
//
//  Created by xiang ying on 14-3-20.
//  Copyright (c) 2014年 xiang ying. All rights reserved.
//

#import "MoreViewController.h"
#import "LanguageViewController.h"
#import "FeedBackViewController.h"
#import "HelpScrollView.h"

@interface MoreViewController ()<UITableViewDataSource,UITableViewDelegate>{
    NSArray *_itemsArray,*_imagesArray;
    UITableView *menu;
}

@end

@implementation MoreViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(languageReset:) name:@"RESETLANGUAGE" object:nil];

    }
    return self;
}

-(void)languageReset:(NSNotification *)noti{
    [self initNavigationItme:[[DataCenter instance] getStringForKey:@"More"]];
    _itemsArray = @[[[DataCenter instance] getStringForKey:@"Language"],
                    [[DataCenter instance] getStringForKey:@"Guide"],
                    [[DataCenter instance] getStringForKey:@"Feedback"],
                    [[DataCenter instance] getStringForKey:@"Version"]];
    [menu reloadData];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self languageReset:nil];
    _imagesArray = @[@"ic-language-selection_09",@"ic-help-guide_09",@"ic-feedback_09",@"ic-check-update_12"];
    
    menu = [[UITableView alloc] initWithFrame:CGRectMake(10, 40, 320-20, 44*4)];
    menu.separatorStyle = UITableViewCellSeparatorStyleNone;
    [menu setBackgroundColor:[UIColor whiteColor]];
    menu.scrollEnabled = NO;
    menu.dataSource = self;
    menu.delegate = self;
    [self.contentView addSubview:menu];

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

-(void)popself{
    [super popself];
    [[UIManagement shareInstance] showLeft];
}

#pragma mark - UITableViewDataSource & UITableViewDelegate

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _itemsArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
        cell.backgroundColor = [UIColor clearColor];
        
        UIImageView *_line = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"list-line_14"]];
        _line.frame = CGRectMake(0, 43, 320, 1);
        [cell addSubview:_line];
    }
    cell.textLabel.text = _itemsArray[indexPath.row];
    cell.imageView.image = [UIImage imageNamed:_imagesArray[indexPath.row]];
    
    cell.detailTextLabel.text = @"";
    
    if (indexPath.row == 0) {
        cell.detailTextLabel.text = ([[DataCenter instance] getLanguageType] == zh_cn)?@"中文":@"English";
    }else if (indexPath.row == _itemsArray.count-1){
        cell.detailTextLabel.text = [[NSBundle mainBundle] infoDictionary][@"CFBundleShortVersionString"];
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    switch (indexPath.row) {
        case 0:{
            //语言选择
            LanguageViewController *language = [[LanguageViewController alloc] init];
            [self.navigationController pushViewController:language animated:YES];
        }
            
            break;
            
        case 1:{
            //使用指南
            HelpScrollView *help = [[HelpScrollView alloc] initWithLanguage:NO];
            help.center = CGPointMake(320+160, help.center.y);
            [self.view.window addSubview:help];
            [UIView animateWithDuration:0.5 animations:^{
                help.center = CGPointMake(160, help.center.y);
            }];
        }
            break;
            
        case 2:{
            //意见反馈
            FeedBackViewController *feedback = [[FeedBackViewController alloc] init];
            [self.navigationController pushViewController:feedback animated:YES];
        }
            break;
            
        case 3:{
            //检查更新
            
        }
            
        default:
            break;
    }
}

@end
